import { http } from "@/common/service/service.js";

/**
 * MES薪资计算API
 */
export const salaryApi = {
  /**
   * 获取员工日薪资统计
   * @param {Object} params 查询参数
   * @param {string} params.employeeId 员工ID
   * @param {string} params.calculationDate 计算日期
   * @returns {Promise}
   */
  getDailySalary(params) {
    const requestParams = {
      employeeId: params.employeeId,
      calculationDate: params.calculationDate || params.date,
    };
    return http.get(
      "/mes/salaryCalculation/calculateDailySalary?employeeId=" +
        params.employeeId +
        "&calculationDate=" +
        params.calculationDate
    );
  },

  /**
   * 获取员工日期范围薪资统计
   * @param {Object} params 查询参数
   * @param {string} params.employeeId 员工ID
   * @param {string} params.startDate 开始日期
   * @param {string} params.endDate 结束日期
   * @returns {Promise}
   */
  getRangeSalary(params) {
    return http.get(
      "/mes/salaryCalculation/calculateRangeSalary?employeeId=" +
        params.employeeId +
        "&startDate=" +
        params.startDate +
        "&endDate=" +
        params.endDate
    );
  },

  /**
   * 获取员工月薪资统计
   * @param {Object} params 查询参数
   * @param {string} params.employeeId 员工ID
   * @param {number} params.year 年份
   * @param {number} params.month 月份
   * @returns {Promise}
   */
  getMonthlySalary(params) {
    return http.get("/mes/salaryCalculation/calculateMonthlySalary", params);
  },

  /**
   * 获取薪资计算记录列表
   * @param {Object} params 查询参数
   * @param {number} params.pageNo 页码
   * @param {number} params.pageSize 每页大小
   * @param {string} params.employeeId 员工ID
   * @param {string} params.calculationDate 计算日期
   * @returns {Promise}
   */
  getSalaryRecords(params) {
    const requestParams = {
      pageNo: params.pageNo || 1,
      pageSize: params.pageSize || 10,
      employeeId: params.employeeId
    };
    
    // 添加日期范围参数
    if (params.startDate) {
      requestParams.startDate = params.startDate;
    }
    if (params.endDate) {
      requestParams.endDate = params.endDate;
    }
    
    return http.get("/mes/salaryCalculation/list", requestParams);
  },
};

export default salaryApi;
